// Evol scripts.
// Authors:
//    Reid
//    Travolta
// Description:
//    Juscare, walking NPC of the Legion of Aemil on the right part of the Agora of Artis.

001-1,118,92,0	script	Juscare#001-1	NPC_HUMAN_MALE_LEGION_ARTIS,{

    function shouldTurn {
        .@tree = findmovegraphlabel("inn_tree");
        .@table = findmovegraphlabel("inter_inn_fav_table");
        if (.movepos == .@tree || .movepos == .@table)
            return 0;
        return 1;
    }

    function localClose {
        if (@Juscar_old_dir > 0)
            .dir = @Juscar_old_dir;
        npc_resumemove;
        close;
    }

    function randomTalk {
        if (Repeat_NPC_lock <= gettimetick(2))
        {
            Repeat_NPC_lock = gettimetick(2) + 2;
            villagertalk;
        }
    }

    npc_pausemove;
    @Juscar_old_dir = -1;
    if (shouldTurn())
    {
        getmapxy(.@map$, .@cx, .@cy, 0);
        @Juscar_old_dir = .dir;
        npc_turntoxy(.@cx, .@cy);
    }

    randomTalk;

    localClose;

OnTimer1000:
    dographmovestep;

OnInit:
    .sex = G_MALE;
    .distance = 4;
    // .debug = 1;
    initmovegraph
        "inn_front",    112,  90,  119, 93,
        "inn_tree",     108,  82,
        "fountain",     87,   85,  91,  86,
        "chelios",      93,   109,
        "chelios_road", 89,   107,
        "chelios",      93,   109,
        "to_market",    76,   119,
        "market",       60,   115, 65,  121,
        "fishing_spot", 109,  127,
        "river_bank",   113,  105,
        "eugene",       112,  115,
        "inn_door",     118,  89,
        "inn_doorstep", 118,  88,
        "inter_inn_doorstep",  29, 43,
        "inter_inn_2tables",   38, 31,
        "inter_inn_fav_table", 51, 33;

    // this is not very obvious stuff
    setmovegraphcmd
        "inn_front",    "inn_door",  1, 0x1,    "flags_0 2; dir 4; call open_door #001-1_118_88",
        "inn_front",    "inn_tree",  2,         "dir 2; wait 1; sit; wait 1; emote 106; wait 20; stand; wait 1",
        "inn_front",    "river_bank",1,         "flags_0 8; flags_1 4",
        "river_bank",   "eugene",    1, 0x4,    "moveon",
        "eugene",       "fishing_spot", 1, 0x4, "wait 7",
        "fishing_spot", "chelios",   1, 0x4,    "dir 6; wait 1; emote 103; wait 10",
        "inn_tree",     "inn_door",  1,         "flags_1 1; flags_0 2; dir 4; call open_door #001-1_118_88",
        "inn_tree",     "fountain",  2,         "dir 4; wait 1; emote 122; wait 10; dir 0; wait 1",
        "fountain",     "chelios_road",         "moveon",
        "chelios_road", "chelios",              "dir 6; wait 1; emote 103; wait 7",
        "chelios",      "eugene",               "flags_1 28; flags_0 4",
        "chelios",      "to_market", 2, 0x20,   "flags_1 20; flags_0 10",
        "to_market",    "market",    1, 0x20,   "flags_1 10; flags_0 20; wait 20",
        "market",       "to_market",            "moveon",
        "to_market",    "chelios",   1, 0x10,   "flags_0 10; dir 6; wait 3",
        "fishing_spot", "eugene",    1, 0x8,    "moveon",
        "eugene",       "river_bank",1, 0x8,    "moveon",
        "river_bank",   "inn_front", 1, 0x8,    "dir 0; wait 5",
        "inn_door",     "inn_doorstep",1, 0x1,  "warp 001-2-28 inter_inn_doorstep; call close_door #001-1_118_88",
        "inter_inn_doorstep",  "inter_inn_2tables",   1, 0x1, "moveon",
        "inter_inn_2tables",   "inter_inn_fav_table", 1, 0x1, "flags_1 2; flags_0 1; dir 6; wait 1; sit; wait 15; stand; wait 1",
        "inter_inn_fav_table", "inter_inn_2tables",   1, 0x2, "moveon",
        "inter_inn_2tables",   "inter_inn_doorstep",  1, 0x2, "call open_door #001-1_118_88; warp 001-1 inn_doorstep",
        "inn_doorstep",        "inn_door",            1, 0x2, "call close_door #001-1_118_88",
        "inn_door",            "inn_front",           1, 0x2, "flags_1 1; flags_0 2; wait 10";

    firstmove "wait 4", "inn_front";
    initnpctimer;
}
